% computes target frequency, target lines and radius 
% for current block size;
% note Parzen window sizes are hard written here
% part of Mt processing codes
% usage [TLine,TLRad,TLFreq,TBand] =  SetTLine(block)
% latest date 07.11.2001
% ~10 years later
% changes made from the original settlin.m
% to get it work with obs time series
%latest date Feb 22, 2011

%#eml
function[TLine,TLRad,TLFreq,TBand] =  settline_h(ProcDef)
  
  DeltaFreq    = ProcDef.DeltaFreq;% Sampling interval in Hz divided by 1024
  MinFreq      = ProcDef.MinFreq;
  MaxFreq      = ProcDef.MaxFreq;
  TLFreq = ProcDef.TLFreq;
  block = ProcDef.block;
  RadSize = ProcDef.RadSize(ProcDef.RdBd);
  TBand = zeros([1,length(TLFreq)]);
  TLine = zeros([1,length(TLFreq)]);
  TLRad = zeros([1,length(TLFreq)]);
  
for Index = 1:length(TLFreq),
    
    TLFreq(Index) =  floor(TLFreq(Index) / DeltaFreq + 0.5)*DeltaFreq;
	TBand(Index) = 1;

    if TLFreq(Index) <= MinFreq,
      TLFreq(Index)  = MinFreq;
    elseif TLFreq(Index) >= MaxFreq,
      TLFreq(Index)  = MaxFreq;
    end;

%    -  set targetlines and band                            
%    -  targetlines are set for block size of 1024 points 

      TLine(Index) =  floor(TLFreq(Index) / DeltaFreq + 0.5);


%   -- set correct targetline in respect to block 

 if block == 64,
	TLine(Index) = round((TLine(Index) +1 ) / 16);
    elseif block == 128,
	TLine(Index) = round((TLine(Index) +1 ) / 8);
	elseif block == 256,
	TLine(Index) = round((TLine(Index) +1) / 4);
	elseif block == 512,
	TLine(Index) = round((TLine(Index)) / 2);
	elseif block == 1024,
	TLine(Index) = TLine(Index);
	elseif block == 2048,
	TLine(Index) = round((TLine(Index) +1) * 2);
	elseif block == 4096,
	TLine(Index) = round((TLine(Index) +1) * 4);
   	elseif block == 8192,
	TLine(Index) = round((TLine(Index) +1) * 8);
	elseif block == 16384,
	TLine(Index) = round((TLine(Index) +1) * 16);
    elseif block == 32768,
	TLine(Index) = round((TLine(Index) +1) * 32);

end;




%------  set radius  ---------------------------------------


	TLRad(Index) = floor(TLine(Index) * RadSize(TBand(Index)) + 0.5 );

%----- check radius boundaries 

 %   if TLRad(Index) < MinParzenRad,
 %     TLRad(Index) = MinParzenRad;
%    elseif TLRad(Index) > MaxParzenRad,
%      TLRad(Index) = MaxParzenRad;
%    end;

end;


% L = TLine - TLRad <= 0;
% 
% if any(L),
%     TLine(L) = [];
%     TLRad(L) = [];
%     TLFreq(L) = [];
%     TBand(L) = [];
% end;
% 
% L = TLine + TRad > block/2;
% 
% TRad(L) = block/2 - TLine(L);

        
  

%Remove the repeated occurances

[a,ia] = unique(TLine);
TLine = TLine(sort(ia,'descend'));
TLRad = TLRad(sort(ia,'descend'));
TLFreq = TLFreq(sort(ia,'descend'));
TBand = TBand(sort(ia,'descend'));
